home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Examples / MiscClassDecoder / MiscClassDecoderMgr.m < prev    next >
Encoding:
Text File  |  1994-12-01  |  2.0 KB  |  85 lines

  1. //
  2. // Time-stamp: <94/12/01 19:31:12 stephan>
  3. //
  4. //    MiscClassDecoderMgr.m -- application's delegate.
  5. //    
  6. //        Written by Stephan Wacker <stephan@rodion.muc.de>
  7. //        Copyright (c) 1994 by Stephan Wacker.
  8. //        Version 1.0  All rights reserved.
  9. //
  10. //        This notice may not be removed from this source code.
  11. //
  12. //    This object is included in the MiscKit by permission from the author
  13. //    and its use is governed by the MiscKit license, found in the file
  14. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  15. //    for a list of all applicable permissions and restrictions.
  16. //    
  17.  
  18.  
  19. #import "MiscClassDecoderMgr.h"
  20.  
  21. #import "MiscClassDecoderSetup.h"    // from a bundle
  22. #import <misckit/MiscClassDecoder.h>
  23.  
  24.  
  25. @implementation MiscClassDecoderMgr
  26.  
  27.  
  28. - defineClass: (id) pasteboard 
  29.     userData: (const char *) userData 
  30.     error: (char **) msg
  31. // Service for defining a given class.
  32. {
  33.     char     *data, *buf;
  34.     int     length;
  35.     
  36.     // Pretend to check the pasteboard types.
  37.     //
  38.     [pasteboard types];
  39.     
  40.     // Read the ASCII data from the pasteboard.
  41.     //
  42.     if( [pasteboard readType: NXAsciiPboardType data: &data
  43.      length: &length] )
  44.     {
  45.         buf = alloca( length+1 );
  46.         strncpy( buf, data, length );
  47.         buf[length] = '\0';
  48.     [decoder analyzeClass: buf];
  49.     }
  50.     else
  51.     {
  52.     *msg = "Error: couldn't read class name from pasteboard.";
  53.     }
  54.     
  55.     return self;
  56. }
  57.  
  58.  
  59. - appDidInit: sender
  60. // Install decoder service.
  61. {
  62.     const char    *myDirectory = [[NXBundle mainBundle] directory];
  63.     const char    *bundleSubdir = "/MiscClassDecoder.bundle";
  64.     char    *buf = (char *) alloca(  strlen(myDirectory)
  65.                        + strlen(bundleSubdir) + 1 );
  66.  
  67.     strcpy( buf, myDirectory );
  68.     strcat( buf, bundleSubdir );
  69.     
  70.     // Load a decoder window from the bundle.
  71.     //
  72.     decoder = [[[ [[NXBundle alloc]
  73.            initForDirectory: buf]
  74.          classNamed: "MiscClassDecoderSetup"] new] decoder];
  75.  
  76.     // Accept service requests.
  77.     //
  78.     [[NXApp appListener] setServicesDelegate: self];
  79.  
  80.     return self;
  81. }
  82.  
  83.  
  84. @end    // MiscClassDecoderMgr
  85.